﻿function UploadImage() {
    this.AllowExt = "jpg|gif|png|bmp";
    //后缀判断  
    this.IsExt = function (url) {
        var sTemp;
        var b = false;
        var s = this.AllowExt.toUpperCase().split("|");
        for (var i = 0; i < s.length; i++) {
            sTemp = url.substr(url.length - s[i].length - 1);
            sTemp = sTemp.toUpperCase();
            s[i] = "." + s[i];
            if (s[i] == sTemp) {
                b = true;
                break;
            }
        }
        return b;
    };
    //以下代码控制图片预览  
    this.Upload = function (sender, divid, imgid) {
        if (!this.IsExt(sender.value)) {
            alert("提示：请选择一个有效的文件，支持的格式有（" + this.AllowExt + "）！");
            return false;
        }
        var objPreview = document.getElementById(divid);
        var objImgview = document.getElementById(imgid);
        if (sender.files && sender.files[0]) {
            // Firefox    
            objImgview.src = sender.files[0].getAsDataURL();
        } else if (objPreview.filters) {
            //IE  
            objPreview.innerHTML = "";
            objPreview.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = sender.value;
        }
    }

}
